package com.open.party.cloud.view.examine

import android.os.Bundle
import android.view.View
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentPagerAdapter
import cn.android.x.parent.AppTitleBaseActivity
import com.open.party.cloud.R
import com.open.party.cloud.view.examine.fragment.ExamineClassForMineListFragment
import com.open.party.cloud.view.examine.fragment.ExamineDoneListFragment
import com.open.party.cloud.view.examine.fragment.ExamineUnSignUpListFragment
import com.open.party.cloud.view.examine.fragment.ExamineUndoneListFragment
import com.sinothk.android.utils.XUtils
import kotlinx.android.synthetic.main.title_tab_view_page.*

class ExamineMainActivity : AppTitleBaseActivity() {
    var titleName = ""
    override fun getLayoutResId(): Int = R.layout.title_tab_view_page

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        titleName = intent.getStringExtra("titleName") as String
        setViewTitle(XUtils.string().getNotNullValue(titleName,"考试云平台"))

        initTabView()
    }

    private fun initTabView() {
        val titleList = ArrayList<String>()
        val fragmentList = ArrayList<Fragment>()

//        titleList.add("报名")
//        titleList.add("未考")
//        titleList.add("已考")
        titleList.add("已考")

//        fragmentList.add(ExamineUnSignUpListFragment())
//        fragmentList.add(ExamineUndoneListFragment())
//        fragmentList.add(ExamineDoneListFragment())

        fragmentList.add(ExamineClassForMineListFragment())

        initTab(
            titleList,
            fragmentList
        )
    }

    private fun initTab(titles: ArrayList<String>, fragments: List<Fragment>) {

        val fragmentPagerAdapter = object : FragmentPagerAdapter(supportFragmentManager, FragmentPagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) {
            override fun getCount(): Int {
                return fragments.size
            }

            override fun getItem(arg0: Int): Fragment {
                return fragments[arg0]
            }
        }

        viewPager.offscreenPageLimit = titles.size - 1
        viewPager.adapter = fragmentPagerAdapter
        //        pager.addOnPageChangeListener(this);
        scrollTab.visibility = View.GONE
        scrollTab.setTitles(titles, true)
//        scrollTab.setNumber(1, "9", View.VISIBLE)//设置数字红点
        scrollTab.setViewPager(viewPager)
        scrollTab.setOnTabListener { index, _ ->
            viewPager.setCurrentItem(index, true)
        }
    }
}